package com.commerce.recording.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.commerce.recording.R;
import com.commerce.recording.Singleton;
import com.commerce.recording.entity.Record;
import com.commerce.recording.entity.Sign;

import java.util.List;
import java.util.Map;

public class MyAllAdapter extends BaseAdapter {
    private List<Record> recordList;
    private Map<String, List<Sign>> signList;
    private boolean openView = false;

    public MyAllAdapter(List<Record> recordList, Map<String, List<Sign>> signList ) {
        this.recordList = recordList;
        this.signList = signList;
    }

    @Override
    public int getCount() {
        return recordList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public static class ViewHolder {

        TextView seeItemText1;
        TextView seeItemText2;
        CheckBox checkBox;

        public ViewHolder(View itemView) {
            this.seeItemText1 = itemView.findViewById(R.id.see_item_text1);
            this.seeItemText2 = itemView.findViewById(R.id.see_item_text2);
            this.checkBox = itemView.findViewById(R.id.see_item_cb);
        }
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.see_list_item, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        //复选框
        if(Singleton.getInstance().isCheck())
            viewHolder.checkBox.setVisibility(View.VISIBLE);
        else
            viewHolder.checkBox.setVisibility(View.INVISIBLE);
        Record record = recordList.get(position);
        viewHolder.seeItemText1.setText(record.getName());
        viewHolder.seeItemText2.setText(record.getTime()+"    ");
        if(signList.containsKey(record.getPath())){
            List<Sign> signs = signList.get(record.getPath());
            viewHolder.seeItemText2.append(signs.size()+"个标记");
        }
        viewHolder.checkBox.setChecked(record.isCheck());
        return convertView;
    }
}
